import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isuserLogin: false,
    currentuser: sessionStorage.getItem('user') || null,
    cartnum: 0,
    XlipstickList: [],
    XmakeupList: [],
    XEXmakeupList: [],
    XperfumeList:[],
    XaddressList:[],
    xtotal:"",
  },
  getters: {
    getIsLogin: state => state.isuserLogin,
    getCurrentuser: state => state.currentuser
  },
  mutations: {
    cartnumSatus(state, number) {
      state.cartnum = number
    },
    userSatus(state, user) {
      if (user) {
        state.currentuser = user;
        sessionStorage.getItem("user", state.currentuser)
        state.isuserLogin = true
      } else {
        state.currentuser = null;
        sessionStorage.removeItem("user")
        state.isuserLogin = false
        state.cartnum = 0
      }
    },
    XlipstickList(state, val) {
      state.XlipstickList = val;
    },
    XmakeupList(state, val) {
      state.XmakeupList = val;
    },
    XEXmakeupList(state, val) {
      state.XEXmakeupList = val;
    },
    XperfumeList(state, val) {
      state.XperfumeList = val;
    },
    XaddressList(state,val){
      state.XaddressList = val;
    },
    xtotal(state,val){
      state.xtotal = val;
    },
    xaddressList(state,val){
      state.xaddressList = val;
    },
  },
  actions: {
    setUser({ commit }, user) {
      commit("userSatus", user)
    },
    lipstickListData(ctx, val) {
      ctx.commit("XlipstickList", val)
    },
    makeupListData(ctx, val) {
      ctx.commit("XmakeupList", val)
    },
    EXmakeupData(ctx,val) {
      ctx.commit("XEXmakeupList", val)
    },
    perfumeData(ctx,val) {
      ctx.commit("XperfumeList", val)
    },
    addressListData(ctx,val){
      ctx.commit("XaddressList", val)
    }
  },
  modules: {
  }
})
